let path = require("path");
let sequelize = require('../config/sequelize');

const modelName = path.basename(__filename, '.js');

const model = sequelize.define(modelName, {

  id: {
    type: sequelize.Sequelize.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    comment: '自增ID'
  },

  filename: {
    type: sequelize.Sequelize.TEXT,
    comment: '文件名'
  },

  user_id: {
    type: sequelize.Sequelize.INTEGER,
    comment: '用户ID'
  },

  directory: {
    type: sequelize.Sequelize.TEXT,
    comment: '文件路径',
    defaultValue: '/'
  },
  
  hash: {
    type: sequelize.Sequelize.STRING,
    comment: 'UserID + Directory + FileName 的 hash 用于同一目录判重'
  },

  file_id: {
    type: sequelize.Sequelize.INTEGER,
    comment: '文件ID'
  },

  file_type: {
    type: sequelize.Sequelize.STRING,
    comment: '文件类型',
    defaultValue: 'unknown'
  },

  is_directory: {
    type: sequelize.Sequelize.BOOLEAN,
    comment: '是否是文件夹'
  },

  is_starred: {
    type: sequelize.Sequelize.BOOLEAN,
    comment: '文件是否收藏'
  },

  is_deleted: {
    type: sequelize.Sequelize.BOOLEAN,
    comment: '文件是否在回收站'
  },

}, {
    underscored: true,
    freezeTableName: true,
    paranoid: true
  });

module.exports = model;
